package com.java.readencoding;

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.*;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.Writer;

public class InputEncoding {
	
	public void  encodingUTF8() throws IOException{
		File file = new File(
				"D:/test/part-m-00000");
		FileInputStream fileInputStream = new FileInputStream(file);
		StringBuffer content = new StringBuffer();
		DataInputStream in = new DataInputStream(fileInputStream);
		BufferedReader d = new BufferedReader(new InputStreamReader(in,"utf-8"));
//		while ((line = d.readLine()) != null){
			
		
		
	}
	
	

	public static void main(String[] args) {
		try {
			File file = new File(
					args[0]);
//			File file = new File(
//					"/root/t00_byftjrn_a.del");
			FileInputStream fileInputStream = new FileInputStream(file);
			StringBuffer content = new StringBuffer();
			DataInputStream in = new DataInputStream(fileInputStream);
			BufferedReader d = new BufferedReader(new InputStreamReader(in,
					"GBK"));// , UTF-8
			String line = null;
			long rowCount =0;
			Writer ow = new OutputStreamWriter(new FileOutputStream(
					"/usr/ADH/data_input/t00_byftjrn_a_utf8.txt"),
					"utf-8");
			while ((line = d.readLine()) != null){
				content.append(line + "\n");
				rowCount++;
				System.out.println(rowCount+" rows transcode");

				if(rowCount%10000==0){
					ow.write(content.toString());
					content= new StringBuffer(); 
				}
			}
			ow.write(content.toString());
			d.close();
			in.close();
			fileInputStream.close();
			ow.close();
			//System.out.println(rowCount+"rows transcode");

		} catch (FileNotFoundException e) {
		
			e.printStackTrace();
		} catch (IOException e) {
			
			e.printStackTrace();
		}

		

	}

}
